package day04;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import util.CookieUtil;

import java.io.IOException;
import java.net.URLEncoder;

@WebServlet("/saveCookie")
public class SaveCookieServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("SaveCookieServlet.service()");


        String username="abc啊";

//        username= URLEncoder.encode(username,"utf-8");
//
//        System.out.println("username = " + username);
//
//        Cookie cookie=new Cookie("username",username);
//
//        cookie.setMaxAge(60*60*24*7);
//
////        cookie.setPath(request.getContextPath()+"/emp");
//
//        response.addCookie(cookie);


        CookieUtil.addCookie("username",username,response);






    }
}
